; *** Fanorona
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

(version "2.0")

(define verify-capture-ok
	(if last-to? ; not the first capture
        (verify (not-last-from? $1)) ; not moving back to last square
		(verify (not-last-from? (opposite $1))) ; not continuing in same direction
    )
)

(define step ($1 (verify empty?) add))
(define approach-capture (
	(verify-capture-ok $1)
    $1
    (verify empty?)
    to
    $1
    (verify enemy?)
    capture
    (while (enemy? $1) $1 capture)
    (add-partial capturing)
))
(define withdrawl-capture (
	(verify-capture-ok $1)
    $1
    (verify empty?)
    to
    back
    (opposite $1)
    (verify enemy?)
    capture
    (while (enemy? (opposite $1)) (opposite $1) capture)
    (add-partial capturing)
))

(game
    (title "迂棋（Fanorona）")
    (description "棋子可沿线移动。若能吃子，必须选择吃子。吃子规则如下：\\[1]撞吃。移动结束后，若在移动方向上有相邻的一个或多个相连的敌棋，则这些敌棋被吃。\
[2]拖吃。若出发位置在移动相反方向上有相邻的一个或多个相连的敌棋，则这些敌棋被吃。\
吃一子后，可以继续连吃或放弃。但每次吃子必须变换方向，且不可返回方才走过的位置。\\吃光对方棋子胜。")
    (history "Fanorona is a 300-year-old game from Madagascar.  There they play
	    that while a piece is in a capturing sequence, it can't return to the 
		same point twice.\\Although the board
        is formed by placing two Alquerque boards side by side, the methods of capture
        are entirely original.  The withdrawal capture was the inspiration for the
        Withdrawer piece in Robert Abbott's chess variant Ultima.")
    (strategy "Multiple captures may be dangerous early in the game, as they open
        up your position to severe counterattacks.  Some positions have diagonal lines
        extending from them.  In the endgame, try to keep your men on these positions,
        to increase their mobility.")
    (option "pass partial" true)
    (click-sound "Audio\\Click4.wav")
    (move-sound "")
    (capture-sound "Audio\\Chirp.wav")
	(players Yellow Orange)
    (turn-order Yellow Orange)
    (move-priorities capturing moving)
    (board
        (image "images\Fanorona\Shaag\Fanorona.bmp" "images\Fanorona\Fanorona.bmp")
        (grid
            (start-rectangle 0 0 54 54); top-left position
            (dimensions ;5 x 9
                ("A/B/C/D/E/F/G/H/I" (64 0)) ; columns
                ("5/4/3/2/1" (0 64)) ; rows
			)
			(directions (n 0 -1) (s 0 1) (e 1 0) (w -1 0))
		)
        (links ne (A1 B2) (A3 B4) (B2 C3) (B4 C5)
                  (C1 D2) (C3 D4) (D2 E3) (D4 E5)
                  (E1 F2) (E3 F4) (F2 G3) (F4 G5)
                  (G1 H2) (G3 H4) (H2 I3) (H4 I5)
        )
        (links nw (B2 A3) (B4 A5) (C1 B2) (C3 B4)
                  (D2 C3) (D4 C5) (E1 D2) (E3 D4)
                  (F2 E3) (F4 E5) (G1 F2) (G3 F4)
                  (H2 G3) (H4 G5) (I1 H2) (I3 H4)
        )
        (links sw (B2 A1) (B4 A3) (C3 B2) (C5 B4)
                  (D2 C1) (D4 C3) (E3 D2) (E5 D4)
                  (F2 E1) (F4 E3) (G3 F2) (G5 F4)
                  (H2 G1) (H4 G3) (I3 H2) (I5 H4)
        )
        (links se (A3 B2) (A5 B4) (B2 C1) (B4 C3)
                  (C3 D2) (C5 D4) (D2 E1) (D4 E3)
                  (E3 F2) (E5 F4) (F2 G1) (F4 G3)
                  (G3 H2) (G5 H4) (H2 I1) (H4 I3)
        )
	)
    (piece
        (image Yellow "images\Fanorona\Shaag\YellowCircle.bmp" "images\Fanorona\YellowCircle.bmp"
               Orange "images\Fanorona\Shaag\OrangeCircle.bmp" "images\Fanorona\OrangeCircle.bmp")
        (name man)
		(help "Man: Steps along lines, captures pieces in it's direction of travel")
		(moves
			(move-type capturing)

			(approach-capture n)
			(approach-capture s)
			(approach-capture e)
			(approach-capture w)
			(approach-capture ne)
			(approach-capture nw)
			(approach-capture se)
			(approach-capture sw)

			(withdrawl-capture n)
			(withdrawl-capture s)
			(withdrawl-capture e)
			(withdrawl-capture w)
			(withdrawl-capture ne)
			(withdrawl-capture nw)
			(withdrawl-capture se)
			(withdrawl-capture sw)

			(move-type moving)

			(step n)
			(step s)
			(step e)
			(step w)
			(step ne)
			(step nw)
			(step se)
			(step sw)
		)			
	)

    (board-setup
        (Orange (man
           A5 B5 C5 D5 E5 F5 G5 H5 I5
           A4 B4 C4 D4 E4 F4 G4 H4 I4
           A3    C3       F3    H3      
		))
		(Yellow (man
              B3    D3       G3    I3
           A2 B2 C2 D2 E2 F2 G2 H2 I2
           A1 B1 C1 D1 E1 F1 G1 H1 I1
		))
	)

      (loss-condition (Yellow Orange) (pieces-remaining 0))
	(loss-condition (Yellow Orange) stalemated)
)

